package com.excilys.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.excilys.dao.IUserDAO;
import com.excilys.model.Account;
import com.excilys.model.User;

/**
 * Class that implements services related to users.
 * 
 * @author excilys dev : SC
 * 
 */

@Service
@Transactional(readOnly = true)
public class UserService {

	@Autowired
	private IUserDAO myUserDAO;

	public IUserDAO getMyUserDAO() {
		return myUserDAO;
	}

	public void setMyUserDAO(IUserDAO myUserDAO) {
		this.myUserDAO = myUserDAO;
	}

	public User getUserByLogin(String name) {
		return myUserDAO.getUserByLogin(name);
	}

	@Transactional(readOnly = false)
	public void addTargetAccountToUser(User u, Account a) {
		myUserDAO.addTargetAccountToUser(u, a);
	}

	@Transactional(readOnly = false)
	public void persistOneUser(User user) {
		myUserDAO.persistOneUser(user);
	}

}
